package com.example.bobo.yuejian322.Activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;

import com.example.bobo.yuejian322.Adapter.OrderAdapter;
import com.example.bobo.yuejian322.Adapter.PeixunAdapter;
import com.example.bobo.yuejian322.Interfa.OrderSeverice;
import com.example.bobo.yuejian322.Interfa.PeixunSeverice;
import com.example.bobo.yuejian322.R;
import com.example.bobo.yuejian322.base.BaseActivity;
import com.example.bobo.yuejian322.bean.Order;
import com.example.bobo.yuejian322.bean.Peixun;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class OrderActivity extends BaseActivity {

    private RecyclerView recyclerView;
    private OrderAdapter adapter;
     private ImageButton back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order);

        recyclerView = (RecyclerView)findViewById(R.id.recyclerView_order);
         back= (ImageButton) findViewById(R.id.order_back);

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://172.24.10.175/workout/api.php/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        OrderSeverice orderSeverice =retrofit.create(OrderSeverice.class);
        Call< List<Order> > listCall = orderSeverice.orderList(191,0,1,userId);
        listCall.enqueue(new Callback<List<Order>>() {
            @Override
            public void onResponse(Call<List<Order>> call, Response<List<Order>> response) {

                List<Order> orderList = response.body();

                if (OrderActivity.this != null) {
                    adapter = new OrderAdapter(OrderActivity.this, orderList);
                    LinearLayoutManager layoutManager = new LinearLayoutManager(OrderActivity.this);
                    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                    recyclerView.setLayoutManager(layoutManager);
                    recyclerView.setAdapter(adapter);
                    recyclerView.setItemAnimator(new DefaultItemAnimator());
                }

            }

            @Override
            public void onFailure(Call<List<Order>> call, Throwable t) {

            }
        });

       back.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               finish();
           }
       });

    }
}
